﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SorketServer
{
    public partial class ImageForm : Form
    {
        public ImageForm()
        {
            InitializeComponent();
            this.Load += ImageForm_Load;
        }

        private void ImageForm_Load(object sender, EventArgs e)
        {
           // CarHelper.Temp();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = ConfigurationManager.AppSettings["path"].ToString();
            System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
            dialog.Description = "请选择Image所在文件夹";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (string.IsNullOrEmpty(dialog.SelectedPath))
                {
                    MessageBox.Show(this, "文件夹路径不能为空", "提示");
                    return;
                }
                string newPath = dialog.SelectedPath;
                var users = CarHelper.GetUsers();
                foreach (var user in users)
                {

                    if (System.IO.File.Exists(path + user.HeadUrl))
                    {
                        string fileName = user.DepartName + "_" + user.UserName;
                        if (System.IO.File.Exists(newPath +"/"+ fileName + ".jpg"))
                        {
                            System.IO.File.Copy(path + user.HeadUrl, newPath+ "/"+ fileName + "1.jpg");
                        }
                        else
                        {
                            System.IO.File.Copy(path + user.HeadUrl, newPath + "/"+ fileName+ ".jpg");
                        }
                      
                    }
                }
                MessageBox.Show("导出成功");
            }
           
        }
    }
}
